Imports Dao
Imports System.Data
Imports DTO
Imports System.Windows.Forms
Public Class QuyenBus
    Inherits AbstractBus
    Public Sub New()
    End Sub
    Public Sub New(ByVal ConnectionString As KetNoiDto)
        ketnoi = ConnectionString
    End Sub
#Region "Xử Lý"
    Public Sub Them(ByVal Dto As Quyendto)
        Dim Dao As New QuyenDao(ketnoi)
        Dao.Them(Dto)
    End Sub
    Public Sub Xoa(ByVal ma As Integer)
        Dim Dao As New QuyenDao(ketnoi)
        Dao.Xoa(ma)
    End Sub
    Public Sub sua(ByVal Dto As Quyendto)
        Dim Dao As New QuyenDao(ketnoi)
        Dao.sua(Dto)
    End Sub
#End Region
    Public Function LayBangTable() As DataTable
        Dim Dao As New QuyenDao(ketnoi)
        Dao.layBang()
        Return Dao
    End Function
    Public Function LayBangTableIlist() As IList
        Dim Dao As New QuyenDao(ketnoi)
        Dim aList As New ArrayList
        For i As Integer = 0 To Dao.Rows.Count - 1
            Dim dtoQuyen As Quyendto = LayBangDTo(i, Dao)
            aList.Add(dtoQuyen)
        Next
        Return aList
    End Function
    Public Function LayBangTableSQL(ByVal sql As String) As DataTable
        Dim Dao As New AbstractDao(sql, sql, ketnoi)
        Return Dao
    End Function
    Public Function LayBangTable(ByVal ma As Integer) As DataTable
        Dim Dao As New QuyenDao(ma, ketnoi)
        Return Dao
    End Function
    Public Function LayBangTableIlist(ByVal ma As Integer) As IList
        Dim Dao As New QuyenDao(ma, ketnoi)
        Dim aList As New ArrayList
        For i As Integer = 0 To Dao.Rows.Count - 1
            Dim dtoQuyen As Quyendto = LayBangDTo(i, Dao)
            aList.Add(dtoQuyen)
        Next
        Return aList
    End Function
    Public Function LayBangTableTheoIdQuyen(ByVal IdQuyen As System.Int32) As DataTable
        Dim Dao As New QuyenDao(ketnoi)
        Dao.layBangTheoIdQuyen(IdQuyen)
        Return Dao
    End Function
    Public Function LayBangTableTheoIdQuyen(ByVal ARRAY1 As ArrayList) As DataTable
        Dim Dao As New QuyenDao(ketnoi)
        Dao.layBangTheoIdQuyen(ARRAY1)
        Return Dao
    End Function
    Public Sub XOAbangTableTheoIdQuyen(ByVal IdQuyen As System.Int32)
        Dim Dao As New QuyenDao(ketnoi)
        Dao.XOABangTheoIdQuyen(IdQuyen)
    End Sub
    Public Function LayBangTableTheoTenQuyen(ByVal TenQuyen As System.String) As DataTable
        Dim Dao As New QuyenDao(ketnoi)
        Dao.layBangTheoTenQuyen(TenQuyen)
        Return Dao
    End Function
    Public Function MaQuyen(ByVal TenQuyen As System.String) As String
        Dim Dao As New QuyenDao(ketnoi)
        Return Dao.MaQuyen(TenQuyen)
    End Function
    Public Function LayBangTableTheoTenQuyen(ByVal ARRAY1 As ArrayList) As DataTable
        Dim Dao As New QuyenDao(ketnoi)
        Dao.layBangTheoTenQuyen(ARRAY1)
        Return Dao
    End Function
    Public Sub XOAbangTableTheoTenQuyen(ByVal TenQuyen As System.String)
        Dim Dao As New QuyenDao(ketnoi)
        Dao.XOABangTheoTenQuyen(TenQuyen)
    End Sub
    Public Function LayBangDTo(ByVal ma As Integer) As Quyendto
        Dim Dao As New QuyenDao(ma, ketnoi)
        Dim dto As New Quyendto
        If Dao.Rows.Count <= 0 Then Return dto
        Try
            If IsDBNull(Dao.Rows(0)("IdQuyen")) = False Then
                dto.IdQuyen = Dao.Rows(0)("IdQuyen")
            End If
        Catch ex As Exception
        End Try
        Try
            If IsDBNull(Dao.Rows(0)("TenQuyen")) = False Then
                dto.TenQuyen = Dao.Rows(0)("TenQuyen")
            End If
        Catch ex As Exception
        End Try
        Return dto
    End Function
    Public Function LayBangDTo(ByVal i As Integer, ByVal dao As DataTable) As Quyendto
        Dim dto As New Quyendto
        If dao.Rows.Count <= 0 Then Return dto
        Try
            If IsDBNull(dao.Rows(i)("IdQuyen")) = False Then
                dto.IdQuyen = dao.Rows(i)("IdQuyen")
            End If
        Catch ex As Exception
        End Try
        Try
            If IsDBNull(dao.Rows(i)("TenQuyen")) = False Then
                dto.TenQuyen = dao.Rows(i)("TenQuyen")
            End If
        Catch ex As Exception
        End Try
        Return dto
    End Function
    Public Function LayBangDTo(ByVal dong As Integer, ByVal dao As DataGridView) As Quyendto
        Dim dto As New Quyendto
        If dao.Rows.Count <= 0 Then Return dto
        For cot As Integer = 0 To dao.Columns.Count - 1
            dto.HoTro(dao.Columns(dong).DataPropertyName, dao.Item(cot, dong).Value)
        Next
        Return dto
    End Function
    Public Function layBangNhieuTable() As DataTable
        Dim Dao As New QuyenDao(ketnoi)
        Dao.layBangNhieuTable()
        Return Dao
    End Function
    Public Sub Taotable()
        Dim Dao As New QuyenDao(ketnoi)
        Dao.TaoTable()
    End Sub
End Class

